<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script src="https://accounts.google.com/gsi/client" onload="console.log('TODO: add onload function')"></script>
        <button onclick="client.requestCode();">Authorize with Google</button>
        <script>
            const client = google.accounts.oauth2.initCodeClient({
                client_id: "809263687381-ofm0eu28sekcj9449r9ueou4b3ksd74a.apps.googleusercontent.com",
                scope: "https://www.googleapis.com/auth/calendar.readonly",
                ux_mode: "popup",
                callback: response => {
                    const xhr = new XMLHttpRequest();
                    xhr.open("POST", code_receiver_uri, true);
                    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                    // Set custom header for CRSF
                    xhr.setRequestHeader("X-Requested-With", "XmlHttpRequest");
                    xhr.onload = function () {
                        console.log("Auth code response: " + xhr.responseText);
                    };
                    xhr.send("code=" + response.code);
                }
            });

            // const client = google.accounts.oauth2.initCodeClient({
            //     client_id: "809263687381-ofm0eu28sekcj9449r9ueou4b3ksd74a.apps.googleusercontent.com",
            //     scope: "https://www.googleapis.com/auth/calendar.readonly",
            //     ux_mode: "redirect",
            //     redirect_uri: "https://m.chainingview.io/jgoogle.html",
            //     state: "YOUR_BINDING_VALUE"
            // });
        </script>
    </body>
</html>
